package com.netease.financial.base.share.action;

import android.content.Context;
import android.os.Bundle;

import com.netease.financial.R;
import com.netease.financial.base.share.model.ShareHolder;
import com.netease.financial.base.web.JSBridge;
import com.tendcloud.tenddata.TCAgent;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by wyf on 6/30/15.
 */
public abstract class BaseShareAction implements ShareAction {

    private static final String KEY_SOURCE_TYPE = "sourceType";

    private JSBridge.Command mCommand;

    public abstract int getIconResId();
    public abstract int getLabelResId();

    @Override
    public boolean share(Context context, ShareHolder holder) {
        Map<String, String> map = new HashMap<>();
        map.put(KEY_SOURCE_TYPE, holder.sourceType);

        TCAgent.onEvent(context, context.getString(R.string.share_text), context.getString(getLabelResId()), map);
        if (mCommand != null) {
            Bundle bundle = new Bundle();
            bundle.putString("result", "success");
            mCommand.setResult(bundle);
            mCommand = null;
        }
        return false;
    }

    public void setCommand(JSBridge.Command command) {
        mCommand = command;
    }
}
